package org.apache.zookeeper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * zookeeper创建线程
 */
public class ZooKeeperThread extends Thread{
    private static final Logger LOG= LoggerFactory.getLogger(ZooKeeperThread.class);
    private UncaughtExceptionHandler uncaughtExceptionHandler=(t,e)->handleException(t.getName(),e);
    public ZooKeeperThread(String threadName){
        super(threadName);
        setUncaughtExceptionHandler(uncaughtExceptionHandler);
    }
    /**
     * This will be used by the uncaught exception handler and just log a
     * warning message and return.
     *
     * @param thName
     *            - thread name
     * @param e
     *            - exception object
     */
    protected void handleException(String thName, Throwable e) {
        LOG.warn("Exception occurred from thread {}", thName, e);
    }

}
